package com.richman.view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;
import java.util.Vector;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableCellRenderer;

import org.json.JSONArray;
import org.json.JSONObject;

import com.richman.controller.AutoBetCentralManager;
import com.richman.controller.BetClient;
import com.richman.controller.SpecialAutoBetCentralManager;
import com.richman.ps38.entity.BetAdyData;
import com.richman.ps38.entity.BetDvalue;
import com.richman.ps38.entity.Event;
import com.richman.ps38.entity.HGEvent;
import com.richman.ps38.entity.HGPS38Event;
import com.richman.ps38.entity.SendData;
import com.richman.utils.Common;
import com.richman.utils.MailManager;
import com.richman.utils.SoundThread;
import com.richman.view.BetLogPane.MyTableModel;

public class BetDvaluePane extends JPanel {
	
	
	
	
	private  Vector<String[]> detailsData = new Vector<String[]>();
	
	
	public SpecialAutoBetCentralManager autobetCtrMng = new SpecialAutoBetCentralManager();
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 189754L;

	long lastbettime = 0;
	
	long lastbetBigtime = 0;


	MyTableModel tableMode = new MyTableModel();
	
	JTable table = null;
	
	Vector<String> emailAlready = new Vector<String>();
	
	Vector<String> betSuccessVec = new Vector<String>();
	
	Vector<String> secondBets = new Vector<String>();
	
	Vector<String> needToBetDXQList = new Vector<String>();	

	Map<String, String> matchTeams = new HashMap<String, String>(); 

	Map<String, Integer> betHistory = new HashMap<String, Integer>(); //HG投注金额
	
	
	
	Vector<String> betSuccessVecPS38 = new Vector<String>();
	
	Vector<String> secondBetsPS38 = new Vector<String>();
	
	Vector<String> redCardsMatch = new Vector<String>();


	Map<String, Integer> betHistoryPS38 = new HashMap<String, Integer>(); 
	
	Map<String, Integer> betHistoryISN = new HashMap<String, Integer>(); 
	
	Map<String, Integer> betHistoryPS38DXQ = new HashMap<String, Integer>();
	
	String eventStr = null;
	boolean getEventStrFin  = false;
	
	
	String eventstrlocal = null;
	boolean getEventStrFinLocal = false;

	public BetDvaluePane() {
		setLayout(new BorderLayout(0, 0));
	    table = new JTable(tableMode);
	    
	    table.getColumnModel().getColumn(0).setPreferredWidth(20);
	    table.getColumnModel().getColumn(1).setPreferredWidth(100);
	    table.getColumnModel().getColumn(2).setPreferredWidth(180);
	    table.getColumnModel().getColumn(3).setPreferredWidth(50);
	    table.getColumnModel().getColumn(4).setPreferredWidth(120);
	    table.getColumnModel().getColumn(5).setPreferredWidth(100);
	    
	    

	    
	    table.setRowHeight(30);
	    
	    table.setFont(new java.awt.Font("黑体", Font.PLAIN, 15));
	    
	    
		JScrollPane scrollPane = new JScrollPane(table);
		add(scrollPane, BorderLayout.CENTER);
	    
		
	}
	
	
	
	public void updateBetDvalueTable(Vector<BetDvalue> betdvalues){
		
		try{
			double specialMinRatio = BetClient.mainWnd.getSpecialMinRatio();
			double newBigMinRatio = BetClient.mainWnd.getNewBigMinRatio();
			double specialDXQMinRatio = BetClient.mainWnd.getSpecialDXQMinRatio();
			int specialBetgold = BetClient.mainWnd.getSpecialBetAmount();
			int newBigBetGold = BetClient.mainWnd.getNewBigBetAmount();
			int specialSecondBetgold = BetClient.mainWnd.getSpecialSecondBetAmount();
			double specialSecondMinRatio = BetClient.mainWnd.getSpecialSecondMinRatio();
			
			int specialDXQBetgold = BetClient.mainWnd.getSpecialDXQBetAmount();
			int specialBetInterval  =BetClient.mainWnd.getspecialBetInterval();
			
			int hgSpecialBetgold = (int) (specialBetgold*0.3);
			int isnSpecialBetgold = (int) (specialBetgold*0.4);
			int ps38SpecialBetgold = (int) (specialBetgold*0.3);
			
			int hgNewBigBetGold = (int) (newBigBetGold*0.3);
			int isnNewBigBetGold = (int) (newBigBetGold*0.4);
			int ps38NewBigBetGold = (int) (newBigBetGold*0.3);
			
			//getBetISN这个标志变为皇冠投注标志
			boolean betHG = BetClient.mainWnd.getBetISN();
			
			//投注ISN和PS38标志
			boolean betPS38 = BetClient.mainWnd.getBetPS38();
			

			
			//测试
		    boolean betNewBig = BetClient.mainWnd.getBetNewBig();
			int newBigBetAmount=BetClient.mainWnd.getNewBigBetAmount();
			boolean betNewBigHalf = BetClient.mainWnd.getNewBigBetHalf();
			boolean betNewBigWhole = BetClient.mainWnd.getNewBigBetWhole();
			
			
			if(detailsData != null) {
				detailsData.clear();
			}
			
			int halfDvalue = BetClient.mainWnd.getdvaluelimit()/2;	//超过一半
			
//			int morethanhalfDvalue = (int) (DaShuiClient.mainWnd.getdvaluelimit()*0.7);	//超级%70
			
			int startIndex = 0;
			
			//只显示达到差值高亮的球赛  开始
			for(int i = 0; i < betdvalues.size(); i++) {
				BetDvalue  bdvalue = betdvalues.elementAt(i);

				if(!bdvalue.team.equals("")) {
					startIndex = i;
				}
				
				if(bdvalue.rqdvalue.contains("/") &&  bdvalue.dxdvalue.contains("/")) {
					if(Integer.parseInt(bdvalue.rqdvalue.split("/")[1]) < BetClient.mainWnd.getdvaluelimit()
							&& Integer.parseInt(bdvalue.dxdvalue.split("/")[1]) < BetClient.mainWnd.getdvaluelimit()) {
						
						for(int j = i; j  >= startIndex; j--) {
							betdvalues.removeElementAt(j);
						}
						
						i = startIndex -1;
						
					}
					
					continue;
					
				}
				
				if(bdvalue.rqdvalue.contains("/") ) {
					if(Integer.parseInt(bdvalue.rqdvalue.split("/")[1]) < BetClient.mainWnd.getdvaluelimit()
							) {
						
						for(int j = i; j  >= startIndex; j--) {
							betdvalues.removeElementAt(j);
						}
						
						i = startIndex -1;
						
					}
					
					continue;
					
				}
				
				if(  bdvalue.dxdvalue.contains("/")) {
					if(Integer.parseInt(bdvalue.dxdvalue.split("/")[1]) < BetClient.mainWnd.getdvaluelimit()) {
						
						for(int j = i; j  >= startIndex; j--) {
							betdvalues.removeElementAt(j);
						}
						
						i = startIndex -1;
						
					}
					
					continue;
					
				}
				
				
			}
			//只显示达到差值高亮的球赛  结束
			
			
			SimpleDateFormat dfSec = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

			int index  = 0;
			
			String currentTeam = "";
			String hgps38BaseScore = "";
			String ps38hgBaseScore = "";
			
			int rqplosetimes = 0;
			int rqpwintimes = 0;
			String processscore = "";
			
			int dxplosetimes = 0;
			int dxpwintimes = 0;
			BetDvalue parsingbdvalue = null;
			int hgps38BiggestDvalue = 0;
			int ps38hgBiggestDvalue = 0;
			
			boolean reachLoseTimesADY = false;
			
			boolean addToShowTableAdy = false;
			
			int bettimesLimit =BetClient.mainWnd.getBettimesLimit(); 
			
			if(BetClient.hasSpecialIllegalBet == true) {
				BetClient.mainWnd.updateMainWndSpecialHasIllegalStatusText(0, "存在非正常投注，已停止投注");;				
				
			}
			
			//按比例投注
			Map<String, Vector<Double>> thisRoundHG12RQPankou = new HashMap<String, Vector<Double>>(); 
			
			Map<String, Vector<Double>> thisRoundHG12DXPankou = new HashMap<String, Vector<Double>>(); 
		
			if(betHG==true && BetClient.hasSpecialIllegalBet == false) {
				
				

			//特殊投注处理   开始		
				Vector<HGEvent> hgEvents = BetClient.betCtrMng.getSpecialAccountInplaybet();
				Vector<HGEvent> processhgevent = new Vector<HGEvent>();
				for(int i = 0; i < betdvalues.size(); i++) {

				BetDvalue  bdvalue = betdvalues.elementAt(i);
				String indexstr = "";
				if(!bdvalue.league.equals("")) {
					processhgevent.clear();
					index++;
					indexstr = Integer.toString(index);
					parsingbdvalue = bdvalue;
					processscore = "";
					hgps38BiggestDvalue = 0;
					ps38hgBiggestDvalue = 0;
					reachLoseTimesADY = false;
					if(hgEvents != null) {
						for(int jj = 0; jj < hgEvents.size(); jj++ ) {
							if(hgEvents.elementAt(jj).eventId.equals(bdvalue.eventid)) {
								processscore = hgEvents.elementAt(jj).homeTeamScore + ":" + hgEvents.elementAt(jj).awayTeamScore;
								processhgevent.add(hgEvents.elementAt(jj));

							}
						}
						
					}
					
//					if(bdvalue.team.contains("布拉加")) {
//						processscore = "2:2";
//					}
					
					
					
					rqplosetimes = 0;
					rqpwintimes = 0;
					
				}
				
				if(!bdvalue.team.equals("")) {
					currentTeam = bdvalue.team;
				}
				
				
				
				String rqhgps38timestr = "";
				String rqps38hgtimestr = "";
				if(bdvalue.rqhgps38times!=0) {

					if(hgps38BiggestDvalue < bdvalue.rqhgps38times) {
						hgps38BiggestDvalue = bdvalue.rqhgps38times;
						hgps38BaseScore = bdvalue.betscore;
					}
					
					
					rqhgps38timestr = currentTeam.split("-vs-")[0] + "/" + Integer.toString(bdvalue.rqhgps38times);
					if(!processscore.equals("") && !processscore.equals("0:0")) {
						//计算投注输赢情况
						double betpankou = Double.parseDouble(bdvalue.rqbetpankou);
						double betscore = 0.0;
						if(bdvalue.betscore.equals(":")||bdvalue.betscore.equals("")) {
							betscore = 0.0;
						}else {
							betscore = Double.parseDouble(bdvalue.betscore.split(":")[0]) - Double.parseDouble(bdvalue.betscore.split(":")[1]);
						}
						
						//double pankou1 = betscore - betpankou;
						double currentscore = Double.parseDouble(processscore.split(":")[0]) - Double.parseDouble(processscore.split(":")[1]);
						
						double score = currentscore - betscore;
						
						if(score < betpankou) {
							rqplosetimes += bdvalue.rqhgps38times;							
						}else if(score > betpankou) {
							rqpwintimes += bdvalue.rqhgps38times;
						}
						
						if(rqplosetimes - rqpwintimes > halfDvalue) {
							reachLoseTimesADY = true;
						}
						
					}
				}
				
				if(bdvalue.rqps38hgtimes!=0) {
					
					if(ps38hgBiggestDvalue < bdvalue.rqps38hgtimes) {
						ps38hgBiggestDvalue = bdvalue.rqps38hgtimes;
						ps38hgBaseScore = bdvalue.betscore;
					}
					
					rqps38hgtimestr = currentTeam.split("-vs-")[1] + "/" + Integer.toString(bdvalue.rqps38hgtimes);
				
				
					if(!processscore.equals("")&& !processscore.equals("0:0")) {
						//计算投注输赢情况
						double betpankou = 0.0 - Double.parseDouble(bdvalue.rqbetpankou);
						double betscore = 0.0;
						if(bdvalue.betscore.equals(":")||bdvalue.betscore.equals("")) {
							betscore = 0.0;
						}else {
							betscore = Double.parseDouble(bdvalue.betscore.split(":")[1]) - Double.parseDouble(bdvalue.betscore.split(":")[0]);
						}
						
						//double pankou1 = betscore - betpankou;
						double currentscore = Double.parseDouble(processscore.split(":")[1]) - Double.parseDouble(processscore.split(":")[0]);
						
						double score = currentscore - betscore;
						
						if(score < betpankou) {
							rqplosetimes += bdvalue.rqps38hgtimes;							
						}else if(score > betpankou) {
							rqpwintimes += bdvalue.rqps38hgtimes;
						}
						
						if(rqplosetimes - rqpwintimes > halfDvalue) {
							reachLoseTimesADY = true;
						}
						
					}
				
				}
				
				String dxhgps38timesrt = "";
				String dxps38hgtimestr = "";
				
				if(bdvalue.dxhgps38times!=0 ) {
					
					dxhgps38timesrt = "大/" + Integer.toString(bdvalue.dxhgps38times);
					
					if(!processscore.equals("")&& !processscore.equals("0:0")) {
						
						int currentballs = Integer.parseInt(processscore.split(":")[0]) + Integer.parseInt(processscore.split(":")[1]);
						
						if(currentballs > Double.parseDouble(bdvalue.dxbetpankou)) {
							
							dxpwintimes+=bdvalue.dxhgps38times;
							
							
						}else if(currentballs < Double.parseDouble(bdvalue.dxbetpankou)) {
							dxplosetimes+=bdvalue.dxhgps38times;
						}
						
					}

					
				}
				
				if(bdvalue.dxps38hgtimes!=0) {
					dxps38hgtimestr = "小/" + Integer.toString(bdvalue.dxps38hgtimes);
					
					if(!processscore.equals("")&& !processscore.equals("0:0")) {
						int currentballs = Integer.parseInt(processscore.split(":")[0]) + Integer.parseInt(processscore.split(":")[1]);
						
						if(currentballs < Double.parseDouble(bdvalue.dxbetpankou)) {
							
							dxpwintimes+=bdvalue.dxps38hgtimes;
							
							
						}else if(currentballs > Double.parseDouble(bdvalue.dxbetpankou)) {
							dxplosetimes+=bdvalue.dxps38hgtimes;
						}
					}
					
					
					
				}
				
				
				
				
				String rqdvaluestr = "";
				
				if(bdvalue.rqdvalue.contains("/")) {
					if(Integer.parseInt(bdvalue.rqdvalue.split("/")[1]) >= BetClient.mainWnd.getdvaluelimit()
							) {
						rqdvaluestr = "<html> <font color='red'>" + bdvalue.rqdvalue + "</font>";
						
						
						//赌的方向被进球了才符合条件 begin
						int hgps38d1 = 0;
						if(hgps38BaseScore.equals("")|| hgps38BaseScore.equals(":")) {
							hgps38d1 = 0;
						}else {
							hgps38d1 = Integer.parseInt(hgps38BaseScore.split(":")[0]) - Integer.parseInt(hgps38BaseScore.split(":")[1]);
						}
						
						int ps38hgd1 = 0;
						if(ps38hgBaseScore.equals("")|| ps38hgBaseScore.equals(":")) {
							ps38hgd1 = 0;
						}else {
							ps38hgd1 = Integer.parseInt(ps38hgBaseScore.split(":")[1]) - Integer.parseInt(ps38hgBaseScore.split(":")[0]);
						}
						
						
						
						int d2 = 0;
						
						if(processscore.equals("")||processscore.equals(":")) {
							d2 = 0;
						}else {
							d2 = Integer.parseInt(processscore.split(":")[0]) - Integer.parseInt(processscore.split(":")[1]);
						}
						
						int ps38hgd2 = 0 - d2;
						
						String dvstr = "";
						
						boolean negativeOnescore = false;
						
						if(bdvalue.rqdvalue.contains(parsingbdvalue.team.split("-vs-")[0]) && d2 < hgps38d1) {
							dvstr = Integer.toString(d2);
							negativeOnescore = true;
						}
						
						if(bdvalue.rqdvalue.contains(parsingbdvalue.team.split("-vs-")[1]) && ps38hgd2 < ps38hgd1) {
							dvstr = Integer.toString(ps38hgd2);
							negativeOnescore = true;
						}
						//赌的方向被进球了才符合条件  end
						
						
						String updownarg = "1";
						if(bdvalue.rqdvalue.contains(parsingbdvalue.team.split("-vs-")[0])) {
							updownarg = "1";
						}
						
						if(bdvalue.rqdvalue.contains(parsingbdvalue.team.split("-vs-")[1])) {
							updownarg = "2";
						}
						
						boolean isSecondBet = false;
						
						int halfOneSidetotalBet = (int) Math.ceil(1.0*Integer.parseInt(bdvalue.rqdvalue.split("/")[1])/2);
						
						//增加皇冠新大小球投注处理
						
						
						//按比例投注    将皇冠大球1大小盘口保存
						Vector<Double> dxpankous = new Vector<Double>();
						for(int ppp = 0; ppp < processhgevent.size()&& ppp<1; ppp++) {
							if(Common.isNum(processhgevent.elementAt(ppp).wholeDXPPankou)) {
								dxpankous.add(Double.parseDouble(processhgevent.elementAt(ppp).wholeDXPPankou));
							}
						}
						if(dxpankous.size()>0) {
							thisRoundHG12DXPankou.put(parsingbdvalue.eventid+"大小球", dxpankous);
						}
						
						//按比例投注
						
						
						if(parsingbdvalue!=null && needToBetDXQList.contains(parsingbdvalue.eventid+processscore) ) {
							int betgold = 0;
							int previousBetgold = 0;
							if(!betHistory.containsKey(parsingbdvalue.eventid + "大小球")) {
								
								
								int bigBetAdyGold = 0;//newBigBetGold;																
								if(betHistoryISN.get(parsingbdvalue.eventid + "大小球")!=null) {
									bigBetAdyGold += betHistoryISN.get(parsingbdvalue.eventid + "大小球");
								}
								if(betHistoryPS38DXQ.get(parsingbdvalue.eventid + "大小球") != null) {
									bigBetAdyGold += betHistoryPS38DXQ.get(parsingbdvalue.eventid + "大小球");
								}
								
								betgold = (int) ((newBigBetGold-bigBetAdyGold)*1.1);
							}else {
								int bigBetAdyGold = 0;//newBigBetGold;
								
								if(betHistory.get(parsingbdvalue.eventid + "大小球") != null) {
									bigBetAdyGold =  (int) (bigBetAdyGold + betHistory.get(parsingbdvalue.eventid + "大小球")/1.1);
								}
								if(betHistoryISN.get(parsingbdvalue.eventid + "大小球")!=null) {
									bigBetAdyGold += betHistoryISN.get(parsingbdvalue.eventid + "大小球");
								}
								if(betHistoryPS38DXQ.get(parsingbdvalue.eventid + "大小球") != null) {
									bigBetAdyGold += betHistoryPS38DXQ.get(parsingbdvalue.eventid + "大小球");
								}
								
								int canBetGold = (int) ((newBigBetGold - bigBetAdyGold)*1.1);
								
								if(betHistory.get(parsingbdvalue.eventid + "大小球") != null && 
										canBetGold > 0) {
									betgold = canBetGold;
									previousBetgold = betHistory.get(parsingbdvalue.eventid + "大小球");									
								}
							}
							
							int betresgold = 0;
							
							HGEvent betevent = processhgevent.elementAt(0);
							
							
							
							
					
								
//							if(!Common.isNum(betevent.wholeDXPPankouUp) ||  
//									Double.parseDouble(betevent.wholeDXPPankouUp) < newBigMinRatio) {
//								
//								for(int ppp = 1; ppp < processhgevent.size()&&ppp<1; ppp++) {
//									if(Common.isNum(processhgevent.elementAt(ppp).wholeDXPPankouUp) &&  
//										Double.parseDouble(processhgevent.elementAt(ppp).wholeDXPPankouUp) > newBigMinRatio ) {
//										betevent = processhgevent.elementAt(ppp);
//										break;
//									}
//								}
//								
//							}
							
								
							if(betgold>0  && System.currentTimeMillis() > lastbettime + 6*1000) {
								
								if(betgold<500)
									betgold = 500;
								
								betresgold = autobetCtrMng.dobetgame("滚球全场大小", "1", betevent, betgold, newBigMinRatio);
								
								lastbettime = System.currentTimeMillis();
								
								if(betresgold > 0) {
									betHistory.put(parsingbdvalue.eventid + "大小球", previousBetgold + betresgold);
									
								}else {
									System.out.println("全场大小bet hg new big failed");
								}
							}
							
							
							
							
							
						}
						//结束
						
						
						if( (rqplosetimes - rqpwintimes >= halfDvalue || reachLoseTimesADY == true) && (rqplosetimes - rqpwintimes >=halfOneSidetotalBet) && parsingbdvalue!= null && 								

								negativeOnescore
								) {
								//||true) {
							//email here
							
							//按比例投注    将皇冠让球1，2盘口保存
							Vector<Double> pankous = new Vector<Double>();
							for(int ppp = 0; ppp < processhgevent.size()&& ppp<2; ppp++) {
								if(Common.isNum(processhgevent.elementAt(ppp).wholerqppankou)) {
									pankous.add(Double.parseDouble(processhgevent.elementAt(ppp).wholerqppankou));
								}
							}
							thisRoundHG12RQPankou.put(parsingbdvalue.eventid+"让球", pankous);
							//按比例投注
							
							
							if(!emailAlready.contains(parsingbdvalue.eventid + "让球" + dvstr) ) {
								Vector<String> mails = BetClient.getMailList();
								
								for(int k = 0, b = 0; k < mails.size()&& b < 50; b++){
									String mail = mails.elementAt(k);
								
									if(true == MailManager.sendMail("240749322@qq.com", "240749322", "beaqekgmzscocbab", mail, "打水 让球盘",  
											parsingbdvalue.league + ":" + parsingbdvalue.team   + "			\n" + bdvalue.rqdvalue.split("/")[0] + "输赢差值：" + Integer.toString(rqplosetimes - rqpwintimes))) {
										k++;
									}else {
										Thread.currentThread().sleep(2000);
										
									}

								}

								System.out.println("让球 email:" + parsingbdvalue.team);
								
								//emailAlready.add(parsingbdvalue.eventid + "让球" + dvstr);
								
//								if(secondBets.contains(parsingbdvalue.eventid + "让球")) {
//									isSecondBet = true;
//								}else {
//									secondBets.add(parsingbdvalue.eventid + "让球");
//								}
								
							}
							
							
							if(!betSuccessVec.contains(parsingbdvalue.eventid + "让球" + dvstr)) {
								if(secondBets.contains(parsingbdvalue.eventid + "让球")) {
									isSecondBet = true;
								}
							}
							
							
							
							//bet here
							
							if(isSecondBet) {
								specialBetgold = specialSecondBetgold;
								specialMinRatio = specialSecondMinRatio;
							}
							
							int betgold = 0;
							int previousBetgold = 0;
							if(!betHistory.containsKey(parsingbdvalue.eventid + "让球" + dvstr)) {
								betgold = hgSpecialBetgold;
								betgold = betgold/BetClient.divider;
								
//								for(int zz = 0; zz < betHistory.size(); zz++) {
//									betHistory
//								}
								
								int alreadybettimes = 0;
								for(String key : betHistory.keySet()){
									if(key.contains("让球")) {
										if(key.split("让球").length > 0 && key.split("让球")[0].equals(parsingbdvalue.eventid)) {
											alreadybettimes++;
										}
									}
									
								}
								
								if(alreadybettimes >= bettimesLimit) {
									betgold = 0;
									System.out.println("超过投注手数限制");
								}
								
							}else {
								if(betHistory.get(parsingbdvalue.eventid + "让球" + dvstr) != null && 
										betHistory.get(parsingbdvalue.eventid + "让球" + dvstr) < hgSpecialBetgold) {
									betgold = hgSpecialBetgold - betHistory.get(parsingbdvalue.eventid + "让球" + dvstr);
									betgold = betgold/BetClient.divider;
									previousBetgold = betHistory.get(parsingbdvalue.eventid + "让球" + dvstr);

								}
							}
							
							
							if(betgold > 0 && !processscore.equals(":")&&processhgevent.size()!=0 && 
									System.currentTimeMillis() > lastbettime + specialBetInterval*1000) {
								
								HGEvent betevent = processhgevent.elementAt(0);
								
								
								
								
								if(updownarg.equals("1")) {
									
									if(!Common.isNum(betevent.wholeRQPPankouUp) ||  
											Double.parseDouble(betevent.wholeRQPPankouUp) < specialMinRatio) {
										
										for(int ppp = 1; ppp < processhgevent.size()&&ppp<2; ppp++) {
											if(Common.isNum(processhgevent.elementAt(ppp).wholeRQPPankouUp) &&  
												Double.parseDouble(processhgevent.elementAt(ppp).wholeRQPPankouUp) > specialMinRatio ) {
												betevent = processhgevent.elementAt(ppp);
												break;
											}
										}
										
									}
									
									
								}else {
									
									if(!Common.isNum(betevent.wholeRQPPankouDown) ||  
											Double.parseDouble(betevent.wholeRQPPankouDown) < specialMinRatio) {
										
										for(int ppp = 1; ppp < processhgevent.size()&&ppp<2; ppp++) {
											if(Common.isNum(processhgevent.elementAt(ppp).wholeRQPPankouDown) &&  
												Double.parseDouble(processhgevent.elementAt(ppp).wholeRQPPankouDown) > specialMinRatio ) {
												betevent = processhgevent.elementAt(ppp);
												break;
											}
										}
										
									}
								}
								
								
								
								int betresgold = 0;
//								if(betHG == true) {
//									betresgold = autobetCtrMng.dobetgameisn("滚球全场让球", updownarg, betevent, betgold, specialMinRatio);
//								}else {
									betresgold = autobetCtrMng.dobetgame("滚球全场让球", updownarg, betevent, betgold, specialMinRatio);
								//}
								
								
								lastbettime = System.currentTimeMillis();
								
								if(betresgold > 0) {
									betHistory.put(parsingbdvalue.eventid + "让球" + dvstr, previousBetgold + betresgold);
									if(!secondBets.contains(parsingbdvalue.eventid + "让球")) {
										secondBets.add(parsingbdvalue.eventid + "让球");
									}
									if(!betSuccessVec.contains(parsingbdvalue.eventid + "让球" + dvstr)) {
										betSuccessVec.add(parsingbdvalue.eventid + "让球" + dvstr);
									}
									
									if(!needToBetDXQList.contains(parsingbdvalue.eventid+processscore) && (previousBetgold + betresgold> hgSpecialBetgold/3*2)) {
										
										Common.logOut(betevent.homeTeam + "   "+ betevent.duringTime);
										
										if((betNewBigHalf==true&&betevent.duringTime.contains("1H")) || betNewBigWhole==true) {
											needToBetDXQList.add(parsingbdvalue.eventid+processscore);
										}
										
										
									}
									
								}else {
									System.out.println("bet HG special failed");
								}
							}
							
							
						}
						
					}else {
						rqdvaluestr = bdvalue.rqdvalue;
					}
					
					hgps38BaseScore = "";
					ps38hgBaseScore = "";
					
				}
				
				
				
				String dxdvaluestr = "";
				
				if(bdvalue.dxdvalue.contains("/")) {
					//old
					//if(Integer.parseInt(bdvalue.dxdvalue.split("/")[1]) >= DaShuiClient.mainWnd.getdvaluelimit()) {
					//new
					
					String updownarg = "";
					
					if(bdvalue.dxdvalue.contains("大")) {
						updownarg = "1";
					}else {
						updownarg = "2";
					}
					
					if(Integer.parseInt(bdvalue.dxdvalue.split("/")[1]) >= BetClient.mainWnd.getspecialDXQMinBet()) {
						
						dxdvaluestr = "<html> <font color='red'>" + bdvalue.dxdvalue + "</font>";
						//old
//					if(dxplosetimes - dxpwintimes > morethanhalfDvalue && parsingbdvalue!= null && 
//						!emailAlready.contains(parsingbdvalue.eventid+"大小")) {
						//new
						if(!emailAlready.contains(parsingbdvalue.eventid+"大小")) {

						
						//email here
					
					Vector<String> mails = BetClient.getMailList();
					
					for(int k = 0, b = 0; k < mails.size()&& b < 50; b++){
						String mail = mails.elementAt(k);
					
					if(true == MailManager.sendMail("240749322@qq.com", "240749322", "beaqekgmzscocbab", mail, "打水 大小盘",  parsingbdvalue.league + ":" + parsingbdvalue.team)) {
						k++;
					}else {
						Thread.currentThread().sleep(2000);
						
					}
					
					
					
				}
					
					System.out.println("neeed to email 大小:" + parsingbdvalue.team);
					
					emailAlready.add(parsingbdvalue.eventid+"大小");
					
				}
						
						
						//赌大小 开始
						//bet here
						int betgold = 0;
						int previousBetgold = 0;
						if(!betHistory.containsKey(parsingbdvalue.eventid + "大小")) {
							betgold = specialDXQBetgold;
						}else {
							if(betHistory.get(parsingbdvalue.eventid + "大小") != null && 
									betHistory.get(parsingbdvalue.eventid + "大小") < specialDXQBetgold) {
								betgold = specialDXQBetgold - betHistory.get(parsingbdvalue.eventid + "大小");
								previousBetgold = betHistory.get(parsingbdvalue.eventid + "大小");
								//BetClient.betCtrMng.useNextAccount();
							}
						}
						
						
						if(betgold > 0 && !processscore.equals(":")&&processhgevent.size()!=0 && 
								System.currentTimeMillis() > lastbettime + specialBetInterval*1000) {
							
							HGEvent betevent = processhgevent.elementAt(0);
							
							
							
							
							if(updownarg.equals("1")) {
								
								if(!Common.isNum(betevent.wholeDXPPankouUp) ||  
										Double.parseDouble(betevent.wholeDXPPankouUp) < specialDXQMinRatio) {
									
									for(int ppp = 1; ppp < processhgevent.size(); ppp++) {
										if(Common.isNum(processhgevent.elementAt(ppp).wholeDXPPankouUp) &&  
											Double.parseDouble(processhgevent.elementAt(ppp).wholeDXPPankouUp) > specialDXQMinRatio ) {
											betevent = processhgevent.elementAt(ppp);
											break;
										}
									}
									
								}
								
								
							}else {
								
								if(!Common.isNum(betevent.wholeDXPPankouDown) ||  
										Double.parseDouble(betevent.wholeDXPPankouDown) < specialDXQMinRatio) {
									
									for(int ppp = 1; ppp < processhgevent.size(); ppp++) {
										if(Common.isNum(processhgevent.elementAt(ppp).wholeDXPPankouDown) &&  
											Double.parseDouble(processhgevent.elementAt(ppp).wholeDXPPankouDown) > specialDXQMinRatio ) {
											betevent = processhgevent.elementAt(ppp);
											break;
										}
									}
									
								}
							}
							
							
							
							int betresgold = betgold;//autobetCtrMng.dobetgame("滚球全场大小", updownarg, betevent, betgold, specialDXQMinRatio);
							
							lastbettime = System.currentTimeMillis();
							
							if(betresgold > 0) {
								betHistory.put(parsingbdvalue.eventid + "大小", previousBetgold + betresgold);
								
							}else {
								System.out.println("全场大小bet special failed");
							}
						}
						//赌大小 结束
						
						
			}else {
						dxdvaluestr = bdvalue.dxdvalue;
					}
					
					hgps38BaseScore = "";
					ps38hgBaseScore = "";
					//processhgevent.clear();
				}
				
				
				//processhgevent.clear();
				
				String[] item = {indexstr, bdvalue.league, bdvalue.team, bdvalue.betscore,
						bdvalue.rqbettype, bdvalue.rqbetpankou, rqhgps38timestr,
						rqps38hgtimestr, rqdvaluestr, bdvalue.dxbettype, 
						bdvalue.dxbetpankou, dxhgps38timesrt, dxps38hgtimestr, 
						dxdvaluestr};
				
				
				detailsData.add(item);
				addToShowTableAdy = true;
				
				
			}//特殊投注处理，结束
			
			}
			
			
			
			//for debug
			boolean isnHasbet = false;
			
			System.out.println(dfSec.format(System.currentTimeMillis()) + ":BDP阶段1");
			
			Vector<String> thisRoundRQPISNBetSuccessTeam = new Vector<String>();
			
			Vector<String> thisRoundDXPISNBetSuccessTeam = new Vector<String>();
			
			
			
			
			
			if(betPS38==true) {//投注ISN
				
				String period = "";
				
				JSONObject inplayRes = BetClient.betCtrMng.getISNEvent();
				
				redCardsMatch.clear();
				
				String hgHometeam = "";
				String hgAwayteam = "";
				
				
				
				System.out.println(dfSec.format(System.currentTimeMillis()) + ":BDP阶段2-1");
				
				
				//String eventStr = null;
				
				Long time1 = System.currentTimeMillis();
				
			     Thread thread = new Thread(new Runnable() {
			         @Override
			         public void run() {
			        	 eventStr = BetClient.betCtrMng.getEventStr("", "");
			        	 getEventStrFin = true;
			         }
			     }, "getEventStrThread");
			     
			     thread.start();
			
				
				while(getEventStrFin == false &&  System.currentTimeMillis() - time1 < 30*1000) {
					
				}
				
				if(getEventStrFin == false) {
					thread.interrupt();
					Common.logOut("强行终止getEventStrThread线程");
				}
				
				if(eventStr==null) {
					Common.logOut("ps38 获取eventStr失败");
				}
				
				getEventStrFin = false;
				
				

				
				System.out.println(dfSec.format(System.currentTimeMillis()) + ":BDP阶段2-2");
				
				

				for(int i = 0; i < betdvalues.size(); i++) {

					BetDvalue  bdvalue = betdvalues.elementAt(i);
					String indexstr = "";
					
					
					
					if(!bdvalue.league.equals("")) {
						//processhgevent.clear();
						index++;
						indexstr = Integer.toString(index);
						parsingbdvalue = bdvalue;
						processscore = "";
						
						hgps38BiggestDvalue = 0;
						ps38hgBiggestDvalue = 0;
						
						
						reachLoseTimesADY = false;
						

						rqplosetimes = 0;
						rqpwintimes = 0;
						
						hgHometeam = bdvalue.team.split("-vs-")[0];
						hgAwayteam = bdvalue.team.split("-vs-")[1];
						
						String isnHometeam = "";
						String isnAwayteam = "";
						
						try {
							BetClient.isnteamsLock.readLock().lock();
							
							for(String[] team: BetClient.isnteams) {

								if(isnHometeam.equals("") && team[0].equals(hgHometeam)) {
									isnHometeam = team[1];
								}
								
								if(isnAwayteam.equals("") && team[0].equals(hgAwayteam)) {
									isnAwayteam = team[1];
								}
								
								if(!isnHometeam.equals("") && !isnAwayteam.equals("")) {
									break;
								}
							}
							
							BetClient.isnteamsLock.readLock().unlock();
							
						}catch(Exception e) {
							BetClient.isnteamsLock.readLock().unlock();
							e.printStackTrace();
						}
						
						boolean canbet = true;
						
						JSONObject isnevent = null;
						if(!isnHometeam.equals("") && !isnAwayteam.equals("")&& inplayRes!=null) {
			    			JSONArray leagues = inplayRes.getJSONObject("schedule").getJSONArray("leagues");
			    			//遍历jsonarray
			    			boolean find = false;
			    			JSONObject event = null;    			
			    			for(int ll = 0; ll< leagues.length(); ll++) {
			    				JSONObject league = leagues.getJSONObject(ll);
			    				JSONArray events = league.getJSONArray("events");
			    				for(int j = 0 ; j < events.length(); j++) {
			    					event = events.getJSONObject(j);
			    					if(event.getString("homeTeam").equals(isnHometeam) && event.getString("awayTeam").equals(isnAwayteam)) {
			    						isnevent = event;
			    						find = true;
			    						break;
			    					}
			    				}
			    				
			    				if(find ==true) {
			    					break;
			    				}
			    			}
						}
						
						if(isnevent != null) {
							processscore = isnevent.getString("score").replace("-", ":");
							period = isnevent.getString("period");
						}else {
							canbet = false;
						}
						
						
					}
					
					if(!bdvalue.team.equals("")) {
						currentTeam = bdvalue.team;
					}
					

					
					String rqhgps38timestr = "";
					String rqps38hgtimestr = "";
					if(bdvalue.rqhgps38times!=0) {

						if(hgps38BiggestDvalue < bdvalue.rqhgps38times) {
							hgps38BiggestDvalue = bdvalue.rqhgps38times;
							hgps38BaseScore = bdvalue.betscore;
						}
						
						
						rqhgps38timestr = currentTeam.split("-vs-")[0] + "/" + Integer.toString(bdvalue.rqhgps38times);
						if(!processscore.equals("") && !processscore.equals("0:0")) {
							//计算投注输赢情况
							double betpankou = Double.parseDouble(bdvalue.rqbetpankou);
							double betscore = 0.0;
							if(bdvalue.betscore.equals(":")||bdvalue.betscore.equals("")) {
								betscore = 0.0;
							}else {
								betscore = Double.parseDouble(bdvalue.betscore.split(":")[0]) - Double.parseDouble(bdvalue.betscore.split(":")[1]);
							}
							
							//double pankou1 = betscore - betpankou;
							double currentscore = Double.parseDouble(processscore.split(":")[0]) - Double.parseDouble(processscore.split(":")[1]);
							
							double score = currentscore - betscore;
							
							if(score < betpankou) {
								rqplosetimes += bdvalue.rqhgps38times;
							}else if(score > betpankou) {
								rqpwintimes += bdvalue.rqhgps38times;
							}
							
							if(rqplosetimes - rqpwintimes > halfDvalue) {
								reachLoseTimesADY = true;
							}
							
						}
					}
					
					if(bdvalue.rqps38hgtimes!=0) {
						
						if(ps38hgBiggestDvalue < bdvalue.rqps38hgtimes) {
							ps38hgBiggestDvalue = bdvalue.rqps38hgtimes;
							ps38hgBaseScore = bdvalue.betscore;
						}
						
						rqps38hgtimestr = currentTeam.split("-vs-")[1] + "/" + Integer.toString(bdvalue.rqps38hgtimes);
					
					
						if(!processscore.equals("")&& !processscore.equals("0:0")) {
							//计算投注输赢情况
							double betpankou = 0.0 - Double.parseDouble(bdvalue.rqbetpankou);
							double betscore = 0.0;
							if(bdvalue.betscore.equals(":")||bdvalue.betscore.equals("")) {
								betscore = 0.0;
							}else {
								betscore = Double.parseDouble(bdvalue.betscore.split(":")[1]) - Double.parseDouble(bdvalue.betscore.split(":")[0]);
							}
							
							//double pankou1 = betscore - betpankou;
							double currentscore = Double.parseDouble(processscore.split(":")[1]) - Double.parseDouble(processscore.split(":")[0]);
							
							double score = currentscore - betscore;
							
							if(score < betpankou) {
								rqplosetimes += bdvalue.rqps38hgtimes;
							}else if(score > betpankou) {
								rqpwintimes += bdvalue.rqps38hgtimes;
							}
							
							if(rqplosetimes - rqpwintimes > halfDvalue) {
								reachLoseTimesADY = true;
							}
							
						}
					
					}
					
					String dxhgps38timesrt = "";
					String dxps38hgtimestr = "";
					
					if(bdvalue.dxhgps38times!=0 ) {
						
						dxhgps38timesrt = "大/" + Integer.toString(bdvalue.dxhgps38times);
						
						if(!processscore.equals("")&& !processscore.equals("0:0")) {
							
							int currentballs = Integer.parseInt(processscore.split(":")[0]) + Integer.parseInt(processscore.split(":")[1]);
							
							if(currentballs > Double.parseDouble(bdvalue.dxbetpankou)) {
								
								dxpwintimes+=bdvalue.dxhgps38times;
								
								
							}else if(currentballs < Double.parseDouble(bdvalue.dxbetpankou)) {
								dxplosetimes+=bdvalue.dxhgps38times;
							}
							
						}

						
					}
					
					if(bdvalue.dxps38hgtimes!=0) {
						dxps38hgtimestr = "小/" + Integer.toString(bdvalue.dxps38hgtimes);
						
						if(!processscore.equals("")&& !processscore.equals("0:0")) {
							int currentballs = Integer.parseInt(processscore.split(":")[0]) + Integer.parseInt(processscore.split(":")[1]);
							
							if(currentballs < Double.parseDouble(bdvalue.dxbetpankou)) {
								
								dxpwintimes+=bdvalue.dxps38hgtimes;
								
								
							}else if(currentballs > Double.parseDouble(bdvalue.dxbetpankou)) {
								dxplosetimes+=bdvalue.dxps38hgtimes;
							}
						}
						
						
						
					}
					
					
					
					
					String rqdvaluestr = "";
					
					if(bdvalue.rqdvalue.contains("/")) {
						if(Integer.parseInt(bdvalue.rqdvalue.split("/")[1]) >= BetClient.mainWnd.getdvaluelimit()
								) {
							rqdvaluestr = "<html> <font color='red'>" + bdvalue.rqdvalue + "</font>";
							
							
							//赌的方向被进球了才符合条件 begin
							int hgps38d1 = 0;
							if(hgps38BaseScore.equals("")|| hgps38BaseScore.equals(":")) {
								hgps38d1 = 0;
							}else {
								hgps38d1 = Integer.parseInt(hgps38BaseScore.split(":")[0]) - Integer.parseInt(hgps38BaseScore.split(":")[1]);
							}
							
							int ps38hgd1 = 0;
							if(ps38hgBaseScore.equals("")|| ps38hgBaseScore.equals(":")) {
								ps38hgd1 = 0;
							}else {
								ps38hgd1 = Integer.parseInt(ps38hgBaseScore.split(":")[1]) - Integer.parseInt(ps38hgBaseScore.split(":")[0]);
							}
							
							
							
							int d2 = 0;
							
							if(processscore.equals("")||processscore.equals(":")) {
								d2 = 0;
							}else {
								d2 = Integer.parseInt(processscore.split(":")[0]) - Integer.parseInt(processscore.split(":")[1]);
							}
							
							int ps38hgd2 = 0 - d2;
							
							String dvstr = "";
							
							boolean negativeOnescore = false;
							
							if(bdvalue.rqdvalue.contains(parsingbdvalue.team.split("-vs-")[0]) && d2 < hgps38d1) {
								dvstr = Integer.toString(d2);
								negativeOnescore = true;
							}
							
							if(bdvalue.rqdvalue.contains(parsingbdvalue.team.split("-vs-")[1]) && ps38hgd2 < ps38hgd1) {
								dvstr = Integer.toString(ps38hgd2);
								negativeOnescore = true;
							}
							//赌的方向被进球了才符合条件  end
							
							
							String updownarg = "1";
							if(bdvalue.rqdvalue.contains(parsingbdvalue.team.split("-vs-")[0])) {
								updownarg = "1";
							}
							
							if(bdvalue.rqdvalue.contains(parsingbdvalue.team.split("-vs-")[1])) {
								updownarg = "2";
							}
							
							boolean isSecondBet = false;
							
							//double ps38ratio = getPs38RPQRatio(hgHometeam, hgAwayteam, updownarg);
							
							//double ps38DXratio = getPs38DXQRatio(hgHometeam, hgAwayteam);
							
							int halfOneSidetotalBet = (int) Math.ceil(1.0*Integer.parseInt(bdvalue.rqdvalue.split("/")[1])/2);
							
							//增加新大小球投注处理
							if(parsingbdvalue!=null && needToBetDXQList.contains(parsingbdvalue.eventid+processscore) && thisRoundHG12DXPankou.get(parsingbdvalue.eventid+"大小球")!=null ) {
								
								int betgold = 0;
								int previousBetgold = 0;
								if(!betHistoryISN.containsKey(parsingbdvalue.eventid + "大小球")) {
									
									int bigBetAdyGold = 0;//newBigBetGold;
									
									if(betHistory.get(parsingbdvalue.eventid + "大小球") != null) {
										bigBetAdyGold = (int) (bigBetAdyGold +  betHistory.get(parsingbdvalue.eventid + "大小球")/1.1);
									}									
									if(betHistoryPS38DXQ.get(parsingbdvalue.eventid + "大小球") != null) {
										bigBetAdyGold += betHistoryPS38DXQ.get(parsingbdvalue.eventid + "大小球");
									}
									
									betgold = newBigBetGold-bigBetAdyGold;									
								}else {
									
									int bigBetAdyGold = 0;//newBigBetGold;
									
									if(betHistory.get(parsingbdvalue.eventid + "大小球") != null) {
										bigBetAdyGold = (int) (bigBetAdyGold + betHistory.get(parsingbdvalue.eventid + "大小球")/1.1);
									}
									if(betHistoryISN.get(parsingbdvalue.eventid + "大小球")!=null) {
										bigBetAdyGold += betHistoryISN.get(parsingbdvalue.eventid + "大小球");
									}
									if(betHistoryPS38DXQ.get(parsingbdvalue.eventid + "大小球") != null) {
										bigBetAdyGold += betHistoryPS38DXQ.get(parsingbdvalue.eventid + "大小球");
									}
									
									int canBetGold = newBigBetGold - bigBetAdyGold;
									
									if(betHistoryISN.get(parsingbdvalue.eventid + "大小球") != null && 
											canBetGold>0) {
										betgold = canBetGold;
										previousBetgold = betHistoryISN.get(parsingbdvalue.eventid + "大小球");
										
									}
								}
								
								int betresgold = 0;
								
								HGEvent betevent = new HGEvent();
								betevent.leagueName = parsingbdvalue.league;
								betevent.homeTeam = parsingbdvalue.team.split("-vs-")[0];
								betevent.awayTeam = parsingbdvalue.team.split("-vs-")[1];
								if(!processscore.equals("") && !processscore.equals(":")) {
									betevent.homeTeamScore = processscore.split(":")[0];
									betevent.awayTeamScore = processscore.split(":")[1];
								}
								betevent.eventTime = period;
								betevent.eventId = parsingbdvalue.eventid;

								if(betgold>0) {
									betresgold = autobetCtrMng.dobetgameisndxq("滚球大小", "1", betevent, betgold, newBigMinRatio, thisRoundHG12DXPankou.get(parsingbdvalue.eventid+"大小球"));
									
									
									if(betresgold > 0) {
										betHistoryISN.put(parsingbdvalue.eventid + "大小球", previousBetgold + betresgold);
										
										
										if(!thisRoundDXPISNBetSuccessTeam.contains(hgHometeam)) {
											thisRoundDXPISNBetSuccessTeam.add(hgHometeam);
										}
										
										
									}else {
										System.out.println("bet ISN newBig failed");
										
										
										
									}
									
								}
								

								
							}
							//结束
							
							//增加2020.10.5 输球手数要超当前投注队一半
							
							if(!processscore.equals(":") && !processscore.equals("")) {
								Common.logOut("ISN bet team:" + hgHometeam + "-vs-" + hgAwayteam);
							}
							
							if((rqplosetimes - rqpwintimes >= halfDvalue || reachLoseTimesADY ==true) && (rqplosetimes - rqpwintimes >= halfOneSidetotalBet)  && parsingbdvalue!= null &&
									
									negativeOnescore 
									) {
									//||true) {
								//email here
								
								

								
								
								if(!betSuccessVecPS38.contains(parsingbdvalue.eventid + "让球" + dvstr)) {
									if(secondBetsPS38.contains(parsingbdvalue.eventid + "让球")) {
										isSecondBet = true;
									}
								}
								
								
								
								//bet here
								
								if(isSecondBet) {
									specialBetgold = specialSecondBetgold;
									specialMinRatio = specialSecondMinRatio;
								}
								
								
								
								int betgold = 0;
								int previousBetgold = 0;
								if(!betHistoryISN.containsKey(parsingbdvalue.eventid + "让球" + dvstr)) {
									betgold = isnSpecialBetgold;
									int alreadybettimes = 0;
									for(String key : betHistoryISN.keySet()){
										if(key.contains("让球")) {
											if(key.split("让球").length > 0 && key.split("让球")[0].equals(parsingbdvalue.eventid)) {
												alreadybettimes++;
											}
										}
										
									}
									
									if(alreadybettimes >= bettimesLimit) {
										betgold = 0;
										System.out.println("ISN超过投注手数限制");
									}

								}else {
									if(betHistoryISN.get(parsingbdvalue.eventid + "让球" + dvstr) != null && 
											betHistoryISN.get(parsingbdvalue.eventid + "让球" + dvstr) < isnSpecialBetgold) {
										betgold = isnSpecialBetgold - betHistoryISN.get(parsingbdvalue.eventid + "让球" + dvstr);
										previousBetgold = betHistoryISN.get(parsingbdvalue.eventid + "让球" + dvstr);
										//BetClient.betCtrMng.useNextAccount();
									}
								}
								
								
								if(betgold > 0 && !processscore.equals(":") && !processscore.equals("") ) {
									
									
									
									
									
								int betresgold = 0;
								
								HGEvent betevent = new HGEvent();
								betevent.leagueName = parsingbdvalue.league;
								betevent.homeTeam = parsingbdvalue.team.split("-vs-")[0];
								betevent.awayTeam = parsingbdvalue.team.split("-vs-")[1];
								if(!processscore.equals("") && !processscore.equals(":")) {
									betevent.homeTeamScore = processscore.split(":")[0];
									betevent.awayTeamScore = processscore.split(":")[1];
								}
								betevent.eventTime = period;
								betevent.eventId = parsingbdvalue.eventid;
//								//TODO remove 暂时是为了让他也去投PS38，之后要删除
//								betgold  = betgold/2;
//								
//								if(betgold < 10000) {
//									betgold = 0;
//								}
//								//TODO remove

								isnHasbet = true;
								
								Vector<Double> hgpanous = thisRoundHG12RQPankou.get(parsingbdvalue.eventid+"让球");
								
								betresgold = autobetCtrMng.dobetgameisn("滚球全场让球", updownarg, betevent, betgold, specialMinRatio, hgpanous);
								
								
								
									
									if(betresgold > 0) {
										betHistoryISN.put(parsingbdvalue.eventid + "让球" + dvstr, previousBetgold + betresgold);
										if(!secondBetsPS38.contains(parsingbdvalue.eventid + "让球")) {
											secondBetsPS38.add(parsingbdvalue.eventid + "让球");
										}
										if(!betSuccessVecPS38.contains(parsingbdvalue.eventid + "让球" + dvstr)) {
											betSuccessVecPS38.add(parsingbdvalue.eventid + "让球" + dvstr);
										}
										
										if(!thisRoundRQPISNBetSuccessTeam.contains(hgHometeam)) {
											thisRoundRQPISNBetSuccessTeam.add(hgHometeam);
										}
										
										
										if(!needToBetDXQList.contains(parsingbdvalue.eventid+processscore) && (previousBetgold + betresgold> isnSpecialBetgold/3*2)) {
											
											if((betNewBigHalf==true&&period.contains("1H")) || betNewBigWhole==true) {
												needToBetDXQList.add(parsingbdvalue.eventid+processscore);
											}
											
											
										}
										
										
									}else {
										System.out.println("bet ISN special failed");
										if(betresgold==-1) {
											redCardsMatch.add(currentTeam);
										}
										
										if(betresgold==-10) {
											Common.logOut(currentTeam+"ps38水位更高");
										}
									}
								}
								
								
							}
							
						}else {
							rqdvaluestr = bdvalue.rqdvalue;
						}
						
						hgps38BaseScore = "";
						ps38hgBaseScore = "";
						
					}
					
					
					
					String dxdvaluestr = "";
					
					if(bdvalue.dxdvalue.contains("/")) {
						//old
						//if(Integer.parseInt(bdvalue.dxdvalue.split("/")[1]) >= DaShuiClient.mainWnd.getdvaluelimit()) {
						//new
						
						String updownarg = "";
						
						if(bdvalue.dxdvalue.contains("大")) {
							updownarg = "1";
						}else {
							updownarg = "2";
						}
						
						if(Integer.parseInt(bdvalue.dxdvalue.split("/")[1]) >= BetClient.mainWnd.getspecialDXQMinBet()) {
							
							dxdvaluestr = "<html> <font color='red'>" + bdvalue.dxdvalue + "</font>";

							//赌大小 开始
							//bet here
							int betgold = 0;
							int previousBetgold = 0;
							if(!betHistoryPS38.containsKey(parsingbdvalue.eventid + "大小")) {
								betgold = specialDXQBetgold;
							}else {
								if(betHistoryPS38.get(parsingbdvalue.eventid + "大小") != null && 
										betHistoryPS38.get(parsingbdvalue.eventid + "大小") < specialDXQBetgold) {
									betgold = specialDXQBetgold - betHistoryPS38.get(parsingbdvalue.eventid + "大小");
									previousBetgold = betHistoryPS38.get(parsingbdvalue.eventid + "大小");
									//BetClient.betCtrMng.useNextAccount();
								}
							}
							
							
							if(betgold > 0 && !processscore.equals(":")&&
									System.currentTimeMillis() > lastbettime + specialBetInterval*1000) {
								
								int betresgold = betgold;//autobetCtrMng.dobetgame("滚球全场大小", updownarg, betevent, betgold, specialDXQMinRatio);
								
								
								
								if(betresgold > 0) {
									betHistoryPS38.put(parsingbdvalue.eventid + "大小", previousBetgold + betresgold);
									
								}else {
									System.out.println("全场大小bet special failed");
								}
							}
							//赌大小 结束
							
							
				}else {
							dxdvaluestr = bdvalue.dxdvalue;
						}
						
						hgps38BaseScore = "";
						ps38hgBaseScore = "";
						//processhgevent.clear();
					}
					
					
					//processhgevent.clear();
					
					String[] item = {indexstr, bdvalue.league, bdvalue.team, bdvalue.betscore,
							bdvalue.rqbettype, bdvalue.rqbetpankou, rqhgps38timestr,
							rqps38hgtimestr, rqdvaluestr, bdvalue.dxbettype, 
							bdvalue.dxbetpankou, dxhgps38timesrt, dxps38hgtimestr, 
							dxdvaluestr};
					if(addToShowTableAdy==false) {
						detailsData.add(item);
					}
					
					
					
					
				}//特殊投注处理，结束
				
				addToShowTableAdy = true;
			}
			
			
			
			System.out.println(dfSec.format(System.currentTimeMillis()) + ":BDP阶段2");
			
			if(betPS38==true) {//投注PS38
				
				String period = "";
				
				try {
					BetClient.sendDatasLock.readLock().lock();
					
					System.out.println(dfSec.format(System.currentTimeMillis()) + ":matchTeams Size:" + matchTeams.size() + ": BetClient.sendDatas size" + BetClient.sendDatas.size());
					
					for(SendData sendData: BetClient.sendDatas) {
						matchTeams.put(sendData.hgevent.homeTeam, sendData.event.homeTeam);
						matchTeams.put(sendData.hgevent.awayTeam, sendData.event.awayTeam);
						
					}
					BetClient.sendDatasLock.readLock().unlock();					
				}catch(Exception e) {
					BetClient.sendDatasLock.readLock().unlock();
					e.printStackTrace();
				}
				
				
				
				Vector<Event> events = null;
				



				String hgHometeam = "";
				String hgAwayteam = "";
				
				for(int i = 0; i < betdvalues.size(); i++) {

					BetDvalue  bdvalue = betdvalues.elementAt(i);
					String indexstr = "";
					String updownarg = "1";
					HGPS38Event betps38event = null;
					
					
					
					boolean canbet = true;
					if(!bdvalue.league.equals("")) {
						//processhgevent.clear();
						
						hgps38BiggestDvalue = 0;
						ps38hgBiggestDvalue = 0;
						index++;
						indexstr = Integer.toString(index);
						parsingbdvalue = bdvalue;
						processscore = "";
						events = null;

						rqplosetimes = 0;
						rqpwintimes = 0;
						
						
						reachLoseTimesADY = false;
						
						
						hgHometeam = bdvalue.team.split("-vs-")[0];
						hgAwayteam = bdvalue.team.split("-vs-")[1];
						
						String ps38HomeTeam = matchTeams.get(hgHometeam);
						String ps38AwayTeam = matchTeams.get(hgAwayteam);
						
						events = BetClient.betCtrMng.getMatches(eventStr, ps38HomeTeam, ps38AwayTeam);
						
						

						if(ps38HomeTeam!=null && ps38AwayTeam!= null) {
							
							
							if(events != null && events.size() > 0) {
								processscore = Integer.toString(events.elementAt(0).homeTeamScore) + ":" + Integer.toString(events.elementAt(0).awayTeamScore);
								period = events.elementAt(0).duringTime;
								
								if(BetClient.mainWnd.getIgnoreRedcard()==false) {
									if(events.elementAt(0).halfDXPPankou.contains("红牌")) {
										processscore = "";
									}
								}
								
								
								//System.out.println(dfSec.format(System.currentTimeMillis()) + bdvalue.team +  ":PS38获取球赛成功.processscore:" + processscore);
							}else {
								//Debug
								
								//System.out.println(dfSec.format(System.currentTimeMillis()) + bdvalue.team + ":PS38获取球赛失败");
							}
						}else {
							//Debug
							if(isnHasbet == true) {
								System.out.println(dfSec.format(System.currentTimeMillis()) + "未找到匹配球队:" + bdvalue.team);
								System.out.println(dfSec.format(System.currentTimeMillis()) + ":matchTeams大小:"  + Integer.toString(matchTeams.size()));
							}

							
						}

						
						if(redCardsMatch.contains(bdvalue.team)) {
							processscore = "";
						}
						
						if(!processscore.equals("")) {
							Common.logOut(hgHometeam + "-vs-" + hgAwayteam + "比分:" + processscore);
						}
						
						
					}
					
					if(!bdvalue.team.equals("")) {
						currentTeam = bdvalue.team;
					}
					

					
					String rqhgps38timestr = "";
					String rqps38hgtimestr = "";
					if(bdvalue.rqhgps38times!=0) {

						if(hgps38BiggestDvalue < bdvalue.rqhgps38times) {
							hgps38BiggestDvalue = bdvalue.rqhgps38times;
							hgps38BaseScore = bdvalue.betscore;
						}
						
						
						rqhgps38timestr = currentTeam.split("-vs-")[0] + "/" + Integer.toString(bdvalue.rqhgps38times);
						if(!processscore.equals("") && !processscore.equals("0:0")) {
							//计算投注输赢情况
							double betpankou = Double.parseDouble(bdvalue.rqbetpankou);
							double betscore = 0.0;
							if(bdvalue.betscore.equals(":")||bdvalue.betscore.equals("")) {
								betscore = 0.0;
							}else {
								betscore = Double.parseDouble(bdvalue.betscore.split(":")[0]) - Double.parseDouble(bdvalue.betscore.split(":")[1]);
							}
							
							//double pankou1 = betscore - betpankou;
							double currentscore = Double.parseDouble(processscore.split(":")[0]) - Double.parseDouble(processscore.split(":")[1]);
							
							double score = currentscore - betscore;
							
							if(score < betpankou) {
								rqplosetimes += bdvalue.rqhgps38times;
							}else if(score > betpankou) {
								rqpwintimes += bdvalue.rqhgps38times;
							}
							if(rqplosetimes - rqpwintimes > halfDvalue) {
								reachLoseTimesADY = true;
							}
							
						}
					}
					
					if(bdvalue.rqps38hgtimes!=0) {
						
						if(ps38hgBiggestDvalue < bdvalue.rqps38hgtimes) {
							ps38hgBiggestDvalue = bdvalue.rqps38hgtimes;
							ps38hgBaseScore = bdvalue.betscore;
						}
						
						rqps38hgtimestr = currentTeam.split("-vs-")[1] + "/" + Integer.toString(bdvalue.rqps38hgtimes);
					
					
						if(!processscore.equals("")&& !processscore.equals("0:0")) {
							//计算投注输赢情况
							double betpankou = 0.0 - Double.parseDouble(bdvalue.rqbetpankou);
							double betscore = 0.0;
							if(bdvalue.betscore.equals(":")||bdvalue.betscore.equals("")) {
								betscore = 0.0;
							}else {
								betscore = Double.parseDouble(bdvalue.betscore.split(":")[1]) - Double.parseDouble(bdvalue.betscore.split(":")[0]);
							}
							
							//double pankou1 = betscore - betpankou;
							double currentscore = Double.parseDouble(processscore.split(":")[1]) - Double.parseDouble(processscore.split(":")[0]);
							
							double score = currentscore - betscore;
							
							if(score < betpankou) {
								rqplosetimes += bdvalue.rqps38hgtimes;
							}else if(score > betpankou) {
								rqpwintimes += bdvalue.rqps38hgtimes;
							}
							if(rqplosetimes - rqpwintimes > halfDvalue) {
								reachLoseTimesADY = true;
							}
						}
					
					}
					
					String dxhgps38timesrt = "";
					String dxps38hgtimestr = "";
					
					if(bdvalue.dxhgps38times!=0 ) {
						
						dxhgps38timesrt = "大/" + Integer.toString(bdvalue.dxhgps38times);
						
						if(!processscore.equals("")&& !processscore.equals("0:0")) {
							
							int currentballs = Integer.parseInt(processscore.split(":")[0]) + Integer.parseInt(processscore.split(":")[1]);
							
							if(currentballs > Double.parseDouble(bdvalue.dxbetpankou)) {
								
								dxpwintimes+=bdvalue.dxhgps38times;
								
								
							}else if(currentballs < Double.parseDouble(bdvalue.dxbetpankou)) {
								dxplosetimes+=bdvalue.dxhgps38times;
							}
							
						}

						
					}
					
					if(bdvalue.dxps38hgtimes!=0) {
						dxps38hgtimestr = "小/" + Integer.toString(bdvalue.dxps38hgtimes);
						
						if(!processscore.equals("")&& !processscore.equals("0:0")) {
							int currentballs = Integer.parseInt(processscore.split(":")[0]) + Integer.parseInt(processscore.split(":")[1]);
							
							if(currentballs < Double.parseDouble(bdvalue.dxbetpankou)) {
								
								dxpwintimes+=bdvalue.dxps38hgtimes;
								
								
							}else if(currentballs > Double.parseDouble(bdvalue.dxbetpankou)) {
								dxplosetimes+=bdvalue.dxps38hgtimes;
							}
						}
						
						
						
					}
					
					
					
					
					String rqdvaluestr = "";
					
					if(bdvalue.rqdvalue.contains("/")) {
						if(Integer.parseInt(bdvalue.rqdvalue.split("/")[1]) >= BetClient.mainWnd.getdvaluelimit()
								) {
							rqdvaluestr = "<html> <font color='red'>" + bdvalue.rqdvalue + "</font>";
							

							
							//赌的方向被进球了才符合条件 begin
							int hgps38d1 = 0;
							if(hgps38BaseScore.equals("")|| hgps38BaseScore.equals(":")) {
								hgps38d1 = 0;
							}else {
								hgps38d1 = Integer.parseInt(hgps38BaseScore.split(":")[0]) - Integer.parseInt(hgps38BaseScore.split(":")[1]);
							}
							
							int ps38hgd1 = 0;
							if(ps38hgBaseScore.equals("")|| ps38hgBaseScore.equals(":")) {
								ps38hgd1 = 0;
							}else {
								ps38hgd1 = Integer.parseInt(ps38hgBaseScore.split(":")[1]) - Integer.parseInt(ps38hgBaseScore.split(":")[0]);
							}
							
							
							
							int d2 = 0;
							
							if(processscore.equals("")||processscore.equals(":")) {
								d2 = 0;
							}else {
								d2 = Integer.parseInt(processscore.split(":")[0]) - Integer.parseInt(processscore.split(":")[1]);
							}
							
							int ps38hgd2 = 0 - d2;
							
							String dvstr = "";
							
							boolean negativeOnescore = false;
							
							if(bdvalue.rqdvalue.contains(parsingbdvalue.team.split("-vs-")[0]) && d2 < hgps38d1) {
								dvstr = Integer.toString(d2);
								negativeOnescore = true;
							}
							
							if(bdvalue.rqdvalue.contains(parsingbdvalue.team.split("-vs-")[1]) && ps38hgd2 < ps38hgd1) {
								dvstr = Integer.toString(ps38hgd2);
								negativeOnescore = true;
							}
							//赌的方向被进球了才符合条件  end
							
							

							
							boolean isSecondBet = false;
							
//							if(isnHasbet == true) {
//								System.out.println(dfSec.format(System.currentTimeMillis()) + currentTeam + " 差值:" + Integer.toString(rqplosetimes - rqpwintimes)
//								+ " negativeOnescore" + Boolean.toString(negativeOnescore));
//							}
							
							boolean isnBetAdy = false;//thisRoundRQPISNBetSuccessTeam.contains(hgHometeam);
							
							int halfOneSidetotalBet = (int) Math.ceil(1.0*Integer.parseInt(bdvalue.rqdvalue.split("/")[1])/2);
							
							
							
							//增加新大小球投注处理
							if(parsingbdvalue!=null && needToBetDXQList.contains(parsingbdvalue.eventid+processscore) &&   
									thisRoundHG12DXPankou.get(parsingbdvalue.eventid+"大小球")!=null) {
								
								Vector<Double> hgdxpankous = thisRoundHG12DXPankou.get(parsingbdvalue.eventid+"大小球");
								
								for(int kkk = 0; kkk< hgdxpankous.size(); kkk++) {
									
									Common.logOut("hg大小球盘口" + (kkk+1) +"盘:" + hgdxpankous.elementAt(kkk));
									
								}
								
								int betgold = 0;
								int previousBetgold = 0;
								if(!betHistoryPS38DXQ.containsKey(parsingbdvalue.eventid + "大小球")) {
									
									int bigBetAdyGold = 0;//newBigBetGold;
									
									if(betHistory.get(parsingbdvalue.eventid + "大小球") != null) {
										bigBetAdyGold = (int) (bigBetAdyGold +  betHistory.get(parsingbdvalue.eventid + "大小球")/1.1);
									}
									if(betHistoryISN.get(parsingbdvalue.eventid + "大小球")!=null) {
										bigBetAdyGold += betHistoryISN.get(parsingbdvalue.eventid + "大小球");
									}
																		
									betgold = newBigBetGold-bigBetAdyGold;
									

								}else {
									
									int bigBetAdyGold = 0;//newBigBetGold;
									
									if(betHistory.get(parsingbdvalue.eventid + "大小球") != null) {
										bigBetAdyGold = (int) (bigBetAdyGold +  betHistory.get(parsingbdvalue.eventid + "大小球")/1.1);
									}
									if(betHistoryISN.get(parsingbdvalue.eventid + "大小球")!=null) {
										bigBetAdyGold += betHistoryISN.get(parsingbdvalue.eventid + "大小球");
									}
									if(betHistoryPS38DXQ.get(parsingbdvalue.eventid + "大小球") != null) {
										bigBetAdyGold += betHistoryPS38DXQ.get(parsingbdvalue.eventid + "大小球");
									}
									
									int canBetGold = newBigBetGold - bigBetAdyGold;
									
									if(betHistoryPS38DXQ.get(parsingbdvalue.eventid + "大小球") != null && 
											canBetGold>0) {
										betgold = canBetGold;
										previousBetgold = betHistoryPS38DXQ.get(parsingbdvalue.eventid + "大小球");
										
									}
								}
								
								
								
								int betresgold = 0;
								
								HGEvent betevent = new HGEvent();
								betevent.leagueName = parsingbdvalue.league;
								betevent.homeTeam = parsingbdvalue.team.split("-vs-")[0];
								betevent.awayTeam = parsingbdvalue.team.split("-vs-")[1];
								if(!processscore.equals("") && !processscore.equals(":")) {
									betevent.homeTeamScore = processscore.split(":")[0];
									betevent.awayTeamScore = processscore.split(":")[1];
								}
								betevent.eventTime = period;
								betevent.eventId = parsingbdvalue.eventid;
								
								

								if(betgold>0) {
									
									
									Event event = null;
									for(int cc = 0; cc < events.size(); cc++) {					
										
										Common.logOut(hgHometeam+"-vs-"+hgAwayteam + "   PS38大球" +(cc+1) + "盘口水位:" + events.elementAt(cc).wholeDXPPankouUp + "  盘口:"+events.elementAt(cc).wholeDXPPankou);
										
											if(Common.isNum(events.elementAt(cc).wholeDXPPankouUp) && 
													(Double.parseDouble(events.elementAt(cc).wholeDXPPankouUp) > newBigMinRatio || Double.parseDouble(events.elementAt(cc).wholeDXPPankouUp) < 0.0
															&& hgdxpankous.contains(Double.parseDouble(events.elementAt(cc).wholeDXPPankou)))
													) {
												event = events.elementAt(cc);
												break;
											}
																		
									}
									
//									if(events.size()>1) {
//										Common.logOut(hgHometeam+"-vs-"+hgAwayteam + "   PS38大球二盘水位:" + events.elementAt(1).wholeDXPPankouUp + "  盘口:"+events.elementAt(1).wholeDXPPankou);
//										if(Common.isNum(events.elementAt(1).wholeDXPPankouUp) && 
//												(Double.parseDouble(events.elementAt(1).wholeDXPPankouUp) > newBigMinRatio || Double.parseDouble(events.elementAt(1).wholeDXPPankouUp) < 0.0)
//												) {
//											event = events.elementAt(1);
//										}
//									}
									
									
									betresgold = autobetCtrMng.dobetgameps38("滚球全场大小", "2", event, betgold, newBigMinRatio);
									
									if(betresgold > 0) {
										
										betHistoryPS38DXQ.put(parsingbdvalue.eventid + "大小球", previousBetgold + betresgold);
										
										
										Common.logOut("投注PS38新大小球成功"+hgHometeam);
										
										
									}else {
										System.out.println("bet PS38 newBig failed");
										
										
										
									}
									
								}
								
								
								
							}
							//结束
							
							if(!processscore.equals("") && !processscore.equals(":")) {
								Common.logOut(hgHometeam + "-vs-" + hgAwayteam + "   parsingbdvalue:" + parsingbdvalue + "   isnBetAdy:" + 
										isnBetAdy  + "     rqplosetimes - rqpwintimes =" + (rqplosetimes - rqpwintimes));
							}
							
							if((rqplosetimes - rqpwintimes >= halfDvalue || reachLoseTimesADY== true) && (rqplosetimes - rqpwintimes >=halfOneSidetotalBet) && parsingbdvalue!= null && 											
									negativeOnescore && !isnBetAdy
									) {
									//||true) {
								//email here
								
								System.out.println(dfSec.format(System.currentTimeMillis()) + "in PS38投注");

								if(bdvalue.rqdvalue.contains(parsingbdvalue.team.split("-vs-")[0])) {
									updownarg = "1";//上盘
								}
								
								if(bdvalue.rqdvalue.contains(parsingbdvalue.team.split("-vs-")[1])) {
									updownarg = "2";//下盘
								}
								

								
								
								

								if(!betSuccessVecPS38.contains(parsingbdvalue.eventid + "让球" + dvstr)) {
									if(secondBetsPS38.contains(parsingbdvalue.eventid + "让球")) {
										isSecondBet = true;
									}
								}
								
								
								
								//bet here
								
								if(isSecondBet) {
									specialBetgold = specialSecondBetgold;
									specialMinRatio = specialSecondMinRatio;
								}
								
								
								
								int betgold = 0;
								int previousBetgold = 0;
								if(!betHistoryPS38.containsKey(parsingbdvalue.eventid + "让球" + dvstr)) {
									betgold = ps38SpecialBetgold;
									
									int alreadybettimes = 0;
									for(String key : betHistoryPS38.keySet()){
										if(key.contains("让球")) {
											if(key.split("让球").length > 0 && key.split("让球")[0].equals(parsingbdvalue.eventid)) {
												alreadybettimes++;
											}
										}
										
									}
									
									if(alreadybettimes >= bettimesLimit) {
										betgold = 0;
										System.out.println("PS38超过投注手数限制");
									}
									
								}else {
									if(betHistoryPS38.get(parsingbdvalue.eventid + "让球" + dvstr) != null && 
											betHistoryPS38.get(parsingbdvalue.eventid + "让球" + dvstr) < ps38SpecialBetgold) {
										betgold = ps38SpecialBetgold - betHistoryPS38.get(parsingbdvalue.eventid + "让球" + dvstr);
										previousBetgold = betHistoryPS38.get(parsingbdvalue.eventid + "让球" + dvstr);
										//BetClient.betCtrMng.useNextAccount();
									}
								}
								
//								if(isnHasbet==true) {
//									System.out.println(dfSec.format(System.currentTimeMillis()) + currentTeam + " 投注金额:" + Integer.toString(betgold)
//									+ " events不为null" + Boolean.toString(events!=null));
//								}
								
								Common.logOut(hgHometeam+"-vs-"+hgAwayteam);
								
											
								Vector<Double> hgpankous = thisRoundHG12RQPankou.get(parsingbdvalue.eventid+"让球");
								Common.logOut("betgold:"+ betgold + "  processscore" + processscore+ "  events:" + events+ "  hgpankous:" + hgpankous);
								
								if(betgold > 0 && !processscore.equals(":") && !processscore.equals("") && events !=null && events.size() >0 && hgpankous!=null) {
									
									int betresgold = 0;
									
									Event event = null;
									
									for(int kkk = 0; kkk< hgpankous.size();kkk++) {
										Common.logOut("hg" +(kkk+1) + "盘口:" + hgpankous.elementAt(kkk));
									}
									
									for(int cc = 0; cc < events.size(); cc++) {
										Common.logOut(cc + ":updownarg:" + updownarg + "," + "wholeRQPPankouUp:" + events.elementAt(cc).wholeRQPPankouUp + ","
												+ "wholeRQPPankouDown:" + events.elementAt(cc).wholeRQPPankouDown+ "wholeRQPPankou:" + events.elementAt(cc).wholerqppankou);
										if(updownarg.equals("1")) {
											if(Common.isNum(events.elementAt(cc).wholeRQPPankouUp) && 
													(Double.parseDouble(events.elementAt(cc).wholeRQPPankouUp) > specialMinRatio || Double.parseDouble(events.elementAt(cc).wholeRQPPankouUp) < 0.0)
													) {
												if(hgpankous.contains(Double.parseDouble(events.elementAt(cc).wholerqppankou))) {
													event = events.elementAt(cc);
													break;
												}
												
											}
										}
										if(updownarg.equals("2")) {
											if(Common.isNum(events.elementAt(cc).wholeRQPPankouDown) && 
													(Double.parseDouble(events.elementAt(cc).wholeRQPPankouDown) > specialMinRatio || Double.parseDouble(events.elementAt(cc).wholeRQPPankouDown) < 0.0)
													) {
												if(hgpankous.contains(Double.parseDouble(events.elementAt(cc).wholerqppankou))) {
													event = events.elementAt(cc);
													break;
												}
												
											}
										}
									}
									
									//优先投注平博二盘
//									if(events.size()>1) {
//										Common.logOut("二盘" + ":updownarg:" + updownarg + "," + "wholeRQPPankouUp:" + events.elementAt(1).wholeRQPPankouUp + ","
//												+ "wholeRQPPankouDown:" + events.elementAt(1).wholeRQPPankouDown+ "wholeRQPPankou:" + events.elementAt(1).wholerqppankou);
//										if(updownarg.equals("1")) {
//											if(Common.isNum(events.elementAt(1).wholeRQPPankouUp) && 
//													(Double.parseDouble(events.elementAt(1).wholeRQPPankouUp) > specialMinRatio || Double.parseDouble(events.elementAt(1).wholeRQPPankouUp) < 0.0)
//													) {
//												if(hgpankous.contains(Double.parseDouble(events.elementAt(1).wholerqppankou))) {
//													event = events.elementAt(1);
//												}
//																							
//											}
//										}
//										if(updownarg.equals("2")) {
//											if(Common.isNum(events.elementAt(1).wholeRQPPankouDown) && 
//													(Double.parseDouble(events.elementAt(1).wholeRQPPankouDown) > specialMinRatio || Double.parseDouble(events.elementAt(1).wholeRQPPankouDown) < 0.0)
//													) {
//												if(hgpankous.contains(Double.parseDouble(events.elementAt(1).wholerqppankou))) {
//													event = events.elementAt(1);
//												}
//											}
//										}
//									}
									
									
									
									System.out.println(dfSec.format(System.currentTimeMillis()) + "in PS38投注2");
									
									betresgold = autobetCtrMng.dobetgameps38("滚球全场让球", updownarg, event, betgold, specialMinRatio);
										
										if(betresgold > 0) {
											betHistoryPS38.put(parsingbdvalue.eventid + "让球" + dvstr, previousBetgold + betresgold);
											if(!secondBetsPS38.contains(parsingbdvalue.eventid + "让球")) {
												secondBetsPS38.add(parsingbdvalue.eventid + "让球");
											}
											if(!betSuccessVecPS38.contains(parsingbdvalue.eventid + "让球" + dvstr)) {
												betSuccessVecPS38.add(parsingbdvalue.eventid + "让球" + dvstr);
											}
											
											
											if(!needToBetDXQList.contains(parsingbdvalue.eventid+processscore) && (previousBetgold + betresgold> ps38SpecialBetgold/3*2)) {
												
												if((betNewBigHalf==true&&period.contains("1H")) || betNewBigWhole==true) {
													needToBetDXQList.add(parsingbdvalue.eventid+processscore);
												}
												
												
											}
											
											
										}else {
											System.out.println("bet ps38 special failed");
										}
								}
								
								
							}
							
						}else {
							rqdvaluestr = bdvalue.rqdvalue;
						}
						
						hgps38BaseScore = "";
						ps38hgBaseScore = "";
						
					}
					
					
					
					String dxdvaluestr = "";
					
					if(bdvalue.dxdvalue.contains("/")) {
						//old
						//if(Integer.parseInt(bdvalue.dxdvalue.split("/")[1]) >= DaShuiClient.mainWnd.getdvaluelimit()) {
						//new
						
						//String updownarg = "";
						
						if(bdvalue.dxdvalue.contains("大")) {
							updownarg = "1";
						}else {
							updownarg = "2";
						}
						
						if(Integer.parseInt(bdvalue.dxdvalue.split("/")[1]) >= BetClient.mainWnd.getspecialDXQMinBet()) {
							
							dxdvaluestr = "<html> <font color='red'>" + bdvalue.dxdvalue + "</font>";
							
							
							
							//赌大小 开始
							//bet here
							int betgold = 0;
							int previousBetgold = 0;
							if(!betHistoryPS38.containsKey(parsingbdvalue.eventid + "大小")) {
								betgold = specialDXQBetgold;
							}else {
								if(betHistoryPS38.get(parsingbdvalue.eventid + "大小") != null && 
										betHistoryPS38.get(parsingbdvalue.eventid + "大小") < specialDXQBetgold) {
									betgold = specialDXQBetgold - betHistoryPS38.get(parsingbdvalue.eventid + "大小");
									previousBetgold = betHistoryPS38.get(parsingbdvalue.eventid + "大小");
									//BetClient.betCtrMng.useNextAccount();
								}
							}
							
							
							if(betgold > 0 && !processscore.equals(":")&&
									System.currentTimeMillis() > lastbettime + specialBetInterval*1000) {
								
								
								
								
								
								int betresgold = betgold;//autobetCtrMng.dobetgame("滚球全场大小", updownarg, betevent, betgold, specialDXQMinRatio);
								
								
								
								if(betresgold > 0) {
									betHistoryPS38.put(parsingbdvalue.eventid + "大小", previousBetgold + betresgold);
									
								}else {
									System.out.println("全场大小bet special failed");
								}
							}
							//赌大小 结束
							
							
				}else {
							dxdvaluestr = bdvalue.dxdvalue;
						}
						
						hgps38BaseScore = "";
						ps38hgBaseScore = "";
						//processhgevent.clear();
					}
					
					
					//processhgevent.clear();
					
					String[] item = {indexstr, bdvalue.league, bdvalue.team, bdvalue.betscore,
							bdvalue.rqbettype, bdvalue.rqbetpankou, rqhgps38timestr,
							rqps38hgtimestr, rqdvaluestr, bdvalue.dxbettype, 
							bdvalue.dxbetpankou, dxhgps38timesrt, dxps38hgtimestr, 
							dxdvaluestr};
					
						if(addToShowTableAdy == false) {
							detailsData.add(item);
						}
						
				}//特殊投注处理，结束
				
				
			}
			
			
			
			
			System.out.println(dfSec.format(System.currentTimeMillis()) + ":BDP阶段3");
			
			
			setOneRowBackgroundColor();
			
			tableMode.updateTable();
			
			
			
			
			
		}catch(Exception e) {
			e.printStackTrace();
		}
		

		
		
		
		
	}
	
	
	
	
	
	
	
	
	
	
	
	
	double getPs38RPQRatio(String hgHometeam, String hgAwayteam, String updownarg) {

		
		String ps38HomeTeam = "";
		String ps38AwayTeam = "";
		

		
		Vector<Event> events = null;
		

		
		ps38HomeTeam = matchTeams.get(hgHometeam);
		ps38AwayTeam = matchTeams.get(hgAwayteam);

		
		if(ps38HomeTeam==null||ps38AwayTeam==null) {
			//Common.logOut("未找到PS38队伍:" + hgHometeam + "-vs-" + hgAwayteam);
			return 3.0;
		}

					
		events = BetClient.betCtrMng.getMatches(eventStr, ps38HomeTeam, ps38AwayTeam);
		
		if(events==null) {
			Common.logOut("events为空:" + hgHometeam + "-vs-" + hgAwayteam);
			Common.logOut("events为空:" + eventStr);
			return 3.0;
		}
		
		//平博优先投注二盘盘口
		if(events.size()>1) {
			if(updownarg.equals("1")) {
				if(Common.isNum(events.elementAt(1).wholeRQPPankouUp) 
						) {
					Common.logOut("平博二盘上盘有水位:" + hgHometeam + "-vs-" + hgAwayteam + "   水位是:" + events.elementAt(1).wholeRQPPankouUp
							+ "    盘口是:" + events.elementAt(1).wholerqppankou);
					return Double.parseDouble(events.elementAt(1).wholeRQPPankouUp);
				}
			}
			if(updownarg.equals("2")) {
				if(Common.isNum(events.elementAt(1).wholeRQPPankouDown) 
						) {
					Common.logOut("平博二盘下盘有水位:" + hgHometeam + "-vs-" + hgAwayteam + "   水位是:" + events.elementAt(1).wholeRQPPankouDown
							+ "    盘口是:" + events.elementAt(1).wholerqppankou);
					return Double.parseDouble(events.elementAt(1).wholeRQPPankouDown);
				}
			}
		}

		
		for(int cc = 0; cc < events.size(); cc++) {
			
			if(updownarg.equals("1")) {
				if(Common.isNum(events.elementAt(cc).wholeRQPPankouUp) 
						) {
					Common.logOut("平博" + (cc+1) + "盘上盘有水位" + hgHometeam + "-vs-" + hgAwayteam+ "   水位是:" + events.elementAt(cc).wholeRQPPankouUp
							+ "    盘口是:" + events.elementAt(cc).wholerqppankou);
					return Double.parseDouble(events.elementAt(cc).wholeRQPPankouUp);
				}
			}
			if(updownarg.equals("2")) {
				if(Common.isNum(events.elementAt(cc).wholeRQPPankouDown) 
						) {
					Common.logOut("平博" + (cc+1) + "盘下盘有水位" + hgHometeam + "-vs-" + hgAwayteam+ "   水位是:" + events.elementAt(cc).wholeRQPPankouDown
							+ "    盘口是:" + events.elementAt(cc).wholerqppankou);
					return Double.parseDouble(events.elementAt(cc).wholeRQPPankouDown);
				}
			}
		}
		
		Common.logOut("平博已无水位:" + hgHometeam + "-vs-" + hgAwayteam + updownarg);
		
		return 3.0;

	}
	
	
	double getPs38DXQRatio(String hgHometeam, String hgAwayteam) {

		
		String ps38HomeTeam = "";
		String ps38AwayTeam = "";
		
		Vector<Event> events = null;
		

		ps38HomeTeam = matchTeams.get(hgHometeam);
		ps38AwayTeam = matchTeams.get(hgAwayteam);
		

		
		if(ps38HomeTeam==null||ps38AwayTeam==null) {
			//Common.logOut("大小球未找到PS38队伍");
			return 3.0;
		}

					
		events = BetClient.betCtrMng.getMatches(eventStr, ps38HomeTeam, ps38AwayTeam);
		
		if(events==null) {
			return 3.0;
		}

		
		//平博优先投注二盘盘口
		if(events.size()>1) {
			if(Common.isNum(events.elementAt(1).wholeDXPPankouUp) 
					) {
				Common.logOut("平博二盘大有水位:" + hgHometeam + "-vs-" + hgAwayteam + "   水位是:" + events.elementAt(1).wholeDXPPankouUp
						+ "    盘口是:" + events.elementAt(1).wholeDXPPankou);
				return Double.parseDouble(events.elementAt(1).wholeDXPPankouUp);
			}	
			
		}
		
		
		for(int cc = 0; cc < events.size(); cc++) {
				if(Common.isNum(events.elementAt(cc).wholeDXPPankouUp) 
						) {
					Common.logOut("平博"+(cc+1)+"盘大有水位:" + hgHometeam + "-vs-" + hgAwayteam + "   水位是:" + events.elementAt(cc).wholeDXPPankouUp
							+ "    盘口是:" + events.elementAt(cc).wholeDXPPankou);
					return Double.parseDouble(events.elementAt(cc).wholeDXPPankouUp);
				}					
		}
		
		return 3.0;

	}
	

	
    public void setOneRowBackgroundColor() {

        try {  
        	
            DefaultTableCellRenderer tcr = new DefaultTableCellRenderer() {
            	
            	
  
                /**
				 * 
				 */
				private static final long serialVersionUID = 123465L;

				public Component getTableCellRendererComponent(JTable table,  
                        Object value, boolean isSelected, boolean hasFocus,  
                        int row, int column) {  

                	
                    if (detailsData.size() > row && detailsData.elementAt(row)[0].equals("")) {  
                    	setBackground(new Color(246,246,246));  
                        
                    }else{  
                        setBackground(new Color(222,222,243));  
                    	//setBackground(new Color(1,1,1));  
                      
                    }  
                    
                    setHorizontalAlignment(JLabel.CENTER);
  
                    return super.getTableCellRendererComponent(table, value,  
                            isSelected, hasFocus, row, column);  
                }  
            };  
            int columnCount = table.getColumnCount();  
            for (int i = 0; i < columnCount; i++) {  
            	table.getColumn(table.getColumnName(i)).setCellRenderer(tcr);
            }  
        } catch (Exception ex) {  
            ex.printStackTrace();  
        }  
    
    }  
    

	
	
	
    public class MyTableModel extends AbstractTableModel  
    {  
    	
    	
    	
    	
    	
    	
        /**
		 * 
		 */
		private static final long serialVersionUID = 10086L;
		/* 
         * 这里和刚才一样，定义列名和每个数据的值 
         */  
        String[] columnNames =          
        	{ "序号", "联赛",   "球队", "比分", "投注类型",  "进球盘口", "主",  "客", "差值", "投注类型 ", "进单盘口", "大", "小", "差值 "};

  
        /** 
         * 构造方法，初始化二维数组data对应的数据 
         */  
        public MyTableModel()  
        {  

        }  
  
        // 以下为继承自AbstractTableModle的方法，可以自定义  
        /** 
         * 得到列名 
         */  
        @Override  
        public String getColumnName(int column)  
        {  
            return columnNames[column];  
        }  
          
        /** 
         * 重写方法，得到表格列数 
         */  
        @Override  
        public int getColumnCount()  
        {  
            return columnNames.length;  
        }  
  
        /** 
         * 得到表格行数 
         */  
        @Override  
        public int getRowCount()  
        {         
	        if(null == detailsData){
	    		return 0;
	    	}
            return detailsData.size();  
        }  
  
        /** 
         * 得到数据所对应对象 
         */  
        @Override  
        public Object getValueAt(int rowIndex, int columnIndex)  
        {  
            //return data[rowIndex][columnIndex];
        	if(detailsData==null || detailsData.size() == 0) {
        		return null;
        	}
        	return detailsData.elementAt(rowIndex)[columnIndex];
        }  
  
        /** 
         * 得到指定列的数据类型 
         */  
        @Override  
        public Class<?> getColumnClass(int columnIndex)  
        {  
        	
        	return String.class;
        	
//        	if(detailsData.size() == 0){
//        		return String.class;
//        	}
//
//            return detailsData.elementAt(0)[columnIndex].getClass();
        	
        }  
  
        /** 
         * 指定设置数据单元是否可编辑.这里设置"姓名","学号"不可编辑 
         */  
        @Override  
        public boolean isCellEditable(int rowIndex, int columnIndex)  
        {  
            return false;
        }  
          
        /** 
         * 如果数据单元为可编辑，则将编辑后的值替换原来的值 
         */  
        @Override  
        public void setValueAt(Object aValue, int rowIndex, int columnIndex)  
        {  
        	if(detailsData.size() > rowIndex) {
                detailsData.elementAt(rowIndex)[columnIndex] = (String)aValue;  
                /*通知监听器数据单元数据已经改变*/  
                fireTableCellUpdated(rowIndex, columnIndex);  
        	}

        }  
        
        public void updateTable(){
        	fireTableDataChanged();
        }
        
  
    }  
	
	
	
	
	
	
}
